package com.briup.facade.web.controller;

import com.briup.common.web.Message;
import com.briup.common.web.MessageUtil;
import com.briup.dataset.entity.Classify;
import com.briup.dataset.entity.Entity;
import com.briup.dataset.service.IClassifyService;
import com.briup.logging.annotation.LoggingAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@LoggingAccess("数据集分类模块")
@RestController
@Api(tags = "数据集分类模块")
public class ClassifyController {

    @Autowired
    private IClassifyService classifyService;

    @LoggingAccess("创建数据集下分类")
    @ApiOperation(value="创建数据集下分类",notes = "参数形式为json")
    @PostMapping(value ="/classify/",consumes = "application/json")
    public Message insertDataset(@RequestBody Classify classify){
        classifyService.insertClassify(classify);
        return MessageUtil.success();
    }
    @GetMapping(value="/classify/showImages/{id}")
    @LoggingAccess("查看该分类下的图片")
    @ApiOperation(value = "查看该分类下的图片",notes = "参数为resuflt风格模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value="分类id",paramType = "path",dataType = "int",required = true)
    })
    public Message showImagesInClassify(@PathVariable("id") Integer id){
        List<Entity> entityList =  classifyService.showImagesInClassify(id);

        return MessageUtil.success(entityList);
    }

    @DeleteMapping(value="/classify/deleteClassifys")
    @LoggingAccess("批量删除该数据集下分类")
    @ApiOperation(value = "批量删除该数据集下分类",notes = "datasetId是为了改变数据集状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "datasetId",value = "数据集id",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "classifyIds",value = "分类id集合",paramType = "query",dataType = "Integer",required = true,allowMultiple = true)
})
    public Message deleteClassifyById(@RequestParam("datasetId") Integer datasetId,@RequestParam("classifyIds") List<Integer> classifyIds){
        classifyService.deleteClassifyById(datasetId,classifyIds);
        return MessageUtil.success();
    }

}
